package com.ruoyi.park.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.omp.api.domain.BuiRoomFacility;
import com.ruoyi.park.service.IBuiRoomFacilityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 配套设施Controller
 *
 * @author cjie
 * @date 2021-08-31
 */
@Api(tags = " 配套设施")
@RestController
@RequestMapping("/buiRoomFacility")
public class BuiRoomFacilityController extends BaseController {
    @Autowired
    private IBuiRoomFacilityService buiRoomFacilityService;

    /**
     * 查询配套设施列表
     */
    @ApiOperation(value="查询配套设施列表", notes="查询配套设施列表")
    @PreAuthorize(hasPermi = "park:buiRoomFacility:list")
    @GetMapping("/list")
    public TableDataInfo list(BuiRoomFacility buiRoomFacility) {
        startPage();
        List<BuiRoomFacility> list = buiRoomFacilityService.selectBuiRoomFacilityList(buiRoomFacility);
        return getDataTable(list);
    }

    /**
     * 导出配套设施列表
     */
    @ApiOperation(value="导出配套设施列表", notes="导出配套设施列表")
    @PreAuthorize(hasPermi = "park:buiRoomFacility:export")
    @Log(title = "配套设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuiRoomFacility buiRoomFacility) throws IOException {
        List<BuiRoomFacility> list = buiRoomFacilityService.selectBuiRoomFacilityList(buiRoomFacility);
        ExcelUtil<BuiRoomFacility> util = new ExcelUtil<BuiRoomFacility>(BuiRoomFacility.class);
        util.exportExcel(response, list, "配套设施数据");
    }
    /**
     * 获取配套设施详细信息
     */
    @ApiOperation(value="获取配套设施详细信息", notes="获取配套设施详细信息")
    @PreAuthorize(hasPermi = "park:buiRoomFacility:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(buiRoomFacilityService.selectBuiRoomFacilityById(id));
    }

    /**
     * 新增配套设施
     */
    @ApiOperation(value="新增配套设施", notes="新增配套设施")
    @PreAuthorize(hasPermi = "park:buiRoomFacility:add")
    @Log(title = "配套设施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuiRoomFacility buiRoomFacility) {
        return toAjax(buiRoomFacilityService.insertBuiRoomFacility(buiRoomFacility));
    }

    /**
     * 修改配套设施
     */
    @ApiOperation(value="修改配套设施", notes="修改配套设施")
    @PreAuthorize(hasPermi = "park:buiRoomFacility:edit")
    @Log(title = "配套设施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuiRoomFacility buiRoomFacility) {
        return toAjax(buiRoomFacilityService.updateBuiRoomFacility(buiRoomFacility));
    }

    /**
     * 删除配套设施
     */
    @ApiOperation(value="删除配套设施", notes="删除配套设施")
    @ApiImplicitParam(name = "ids", value = "配套设施ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "park:buiRoomFacility:remove")
    @Log(title = "配套设施", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(buiRoomFacilityService.deleteBuiRoomFacilityByIds(ids));
    }
}
